<html>

<head>

<title>
 
SENAI Fall!

</title>

<script src="js/sceneintro.js"></script>
<script src="js/scenecredits.js"></script>
<script src="js/button.js"></script>

</head>

<body>

<!--canvas principal onde acontece o jogo-->
<canvas width="800" height="600" id="main" style="border:1px solid #000000;"></canvas>

<script>

var canvas = document.getElementById("main");
var screen = canvas.getContext("2d");

var SCREENWIDTH = 800;
var SCREENHEIGHT = 600;

var paused = false;

var intro = new SceneIntro();

var credits = new SceneCredits();

//var level01 = new SceneLevel01();

var SCENES = { INTRO: 0, CREDITS: 1, LEVEL01: 2 }

var currentScene = SCENES.INTRO;

load();

function load()
{	
	console.log("load");
	
	if((true))//to do...
	{	
		console.log("carreguei");
	
		loop();
	}
	else
	{
		console.log("nao carreguei");
	
		setTimeout(load, 30 );
	}
}

function loop()
{
	//console.log("loop");
	
	//o loop do jogo faz chamadas para update e draw
	
	update();
	
	draw();
	
	//o loop do jogo se chama a cada 30 ms, +- 30 FPS (1/30) ~ 33 fps
	setTimeout(loop, 1000/60 );
	
}	
	
function update()
{	
	switch(currentScene)
	{
		case SCENES.INTRO:
		{
			intro.update();		
		}
		break;
		case SCENES.CREDITS:
		{
			credits.update();
		}
		break;
		//case SCENES.LEVEL01:
		//{
		//	level01.update();
		//}
		//break;
	}
}

function draw()
{
	clear();
	
	switch(currentScene)
	{
		case SCENES.INTRO:
		{
			intro.draw();
		}
		break;
		case SCENES.CREDITS:
		{
			credits.draw();
		}
		break;
		//case SCENES.LEVEL01:
		//{
		//	level01.draw();
		//}
		//break;
	}
		
}

function clear()
{
	screen.clearRect(0,0,800,600);
}

window.addEventListener('keydown', key_down, true);
window.addEventListener('keyup', key_up, true);
window.addEventListener('mousemove', mouse_move, true);
window.addEventListener('mouseup', mouse_up, true);
window.addEventListener('mousedown', mouse_down, true);

function key_down(key)
{
	switch(currentScene)
	{
		case SCENES.INTRO:
		{
			intro.key_down(key);
		}
		break;
		case SCENES.CREDITS:
		{
			credits.key_down(key);
		}
		break;
		//case SCENES.LEVEL01:
		//{
		//	level01.key_down(key);
		//}
		//break;
	}
}

function key_up(key)
{
	switch(currentScene)
	{
		case SCENES.INTRO:
		{
			intro.key_up(key);
		}
		break;
		case SCENES.CREDITS:
		{
			credits.key_up(key);
		}
		break;
		//case SCENES.LEVEL01:
		//{
		//	level01.key_up(key);
		//}
		//break;
	}	
}

function mouse_move(mouse)
{
	
}

function mouse_up(mouse)
{
	
}

function mouse_down(mouse)
{
	switch(currentScene)
	{
		case SCENES.INTRO:
		{
			intro.mouse_down(mouse);
		}
		break;
		case SCENES.CREDITS:
		{
			credits.mouse_down(mouse);
		}
		break;
		//case SCENES.LEVEL01:
		//{
		//	level01.mouse_down(mouse);
		//}
		//break;
	}
}

function Collide(x1, y1, w1, h1, x2, y2, w2, h2)
{	
	if((x1+w1<x2)//se rect1 esquerda rect2
		||(x1>x2+w2)//se rect1 direita rect2
		||(y1+h1<y2)//se rect1 acima rect2
		||(y1>y2+h2))//se rect1 abaixo rect2
	{
		return false;//nao colidiu
	}
	else
	{
		return true;//colidiu
	}
}


</script>

</body>

</html>